<?php
namespace app\common\model;
use think\Model;
/**
 * 
 */
class ShopSort extends Model
{
	// 开启自动写入时间戳
    protected $autoWriteTimestamp = true;
    // 定义时间戳字段名
    protected $createTime = 'ctime';
    /**
     * 时间范围查询
     * @param  [type] $query [description]
     * @param  [type] $value [description]
     * @param  [type] $data  [description]
     * @return [type]        [description]
     */
    public function searchCtimeAttr($query,$value, $data)
    {
        $start=$value[0]?strtotime($value[0]):0;
        $end=$value[1]?strtotime($value[1]):0;
        if(!empty($start)&&!empty($end)){
            $query->where('ctime','between',[$start,$end]);
        }elseif(!empty($start)&&empty($end)){
            $query->where('ctime','>',$start);
        }elseif(empty($start)&&!empty($end)){
            $query->where('ctime','<',$end);
        }
    }
    /**
     * 状态查询
     * @param  [type] $query [description]
     * @param  [type] $value [description]
     * @param  [type] $data  [description]
     * @return [type]        [description]
     */
    public function searchStatusAttr($query,$value, $data)
    {
        if(strlen($value)){
            $query->where('status',$value);
        }       
    }
    /**
     * 关键字查询
     * @param  [type] $query [description]
     * @param  [type] $value [description]
     * @param  [type] $data  [description]
     * @return [type]        [description]
     */
    public function searchNameAttr($query,$value, $data)
    {
        if(!empty($value)){
            $query->where('id|name',$value);
        }
    }
    /**
     * 获取店铺类目
     */
    public function getList(){
        $list=$this->where(['status'=>1,'pid'=>0])->order('sort asc')->select();
        return $list;
    }
}